POV-Ray : Newsgroups : povray.off-topic : Programming langauges : Re: Programming langauges Server Time
5 Sep 2024 09:26:34 EDT (-0400)
  Re: Programming langauges  
From: Darren New
Date: 22 Oct 2009 16:54:00
Message: <4ae0c668$1@news.povray.org>
Captain Jack wrote:
> Wouldn't bit fields do what you're describing?

Only if they're all aligned to byte boundaries, and you know what order the 
fields are in. I.e., yes, but in no way portably. There's no way to portably 
(for example) lay a C structure for an IP datagram header onto the header 
and just use it.

Contrast with (say) Ada, where you can say

type FatTable = packed array[0..1000] of integer 0..4095;

and automatically get instructions that pack and unpack 12-bit entries in 
your array of memory.  (Modulo syntax, mind. :-)

Ada also supports context switching, interrupt handling, defined ways of 
pointing to particular areas of memory (i.e., so you can tell the linker to 
put the machine registers at a particular place), arbitrary ranges for 
integers, for floats, and for decimal numbers. (i.e., you tell Ada what 
range/precision you need, and it picks the best representation, instead of 
trying to find the best representation from amongst the things the compiler 
offers.) It supports prioritized interrupt handling, including blocking 
lower-level interrupts while a higher-level one is running, handling 
priority inversion, and scheduling threads based on the same priorities as 
interrupts. It also supports volatile variables (which might be changed by 
hardware) and atomic operations (where you can guarantee that if you're 
writing a 2-byte integer, you won't get an instruction that stores the value 
using two 1-byte store instructions, which is also important for hardware), 
and "protected" operations that take advantage of hardware instructions for 
blocking multiple threads (i.e., which take advantage of hardware locks).

I don't think C handles *any* of that. About the closest it comes is 
volatile (sort of) and undefined behavior that *often* does what you'd 
expect when using addresses, unless your memory model is too far different 
from C's.


-- 
   Darren New, San Diego CA, USA (PST)
   I ordered stamps from Zazzle that read "Place Stamp Here".


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.